package com.example.view.module.design;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.common.base.AbsActivity;
import com.example.view.R;
import com.example.view.databinding.ActDesignNestedVpBinding;
import com.example.view.module.design.adapter.NestedViewAdapter;
import com.example.view.module.design.fragment.EmptyFragment;

import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 */
@Route(path = "/view/nestedViewPager")
public class NestedViewpagerActivity extends AbsActivity<ActDesignNestedVpBinding> {

    @Override
    protected int getLayoutId() {
        return R.layout.act_design_nested_vp;
    }

    @Override
    protected void main() {
        setSupportActionBar(mBinding.toolbar);
        //返回主页的按钮
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(EmptyFragment.getInstance());
        fragments.add(EmptyFragment.getInstance());
        fragments.add(EmptyFragment.getInstance());
        fragments.add(EmptyFragment.getInstance());
        //TabLayout+ViewPager
        NestedViewAdapter mAdapter = new NestedViewAdapter(getSupportFragmentManager(), fragments);
        mBinding.viewpager.setOffscreenPageLimit(4);
        mBinding.viewpager.setAdapter(mAdapter);
        mBinding.tabLayout.setupWithViewPager(mBinding.viewpager);
        //ViewPager切换时NestedScrollView滑动到顶部
        mBinding.viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
//                mBinding.nestedScroll.scrollTo(0, 0);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    protected void initListener() {

    }
}
